/**
 * Created by zhanghan on 2017/12/8
 * 角色管理
 * Updated by yangxiao2 on 2019/10/30 角色用户新增、剔除
 */
define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/content/systemManager/roleManage/roleManage.js',
  './custom/widgets/js/YufpUserSelector.js',
  './custom/widgets/js/yufpOrgTree.js',
  './custom/widgets/js/yufpExtTree.js',
  './custom/widgets/js/yufpTemplateSelector.js'// 数据权限模板选择器  add by chenlin
],
function (require, exports) {
  // page加载完成后调用ready方法
  exports.ready = function (hashCode, data, cite) {
    yufp.lookup.reg('DATA_STS');
    var orgId = '';
    yufp.custom.vue({
      el: '#roleManage',
      data: function () {
        var me = this;
        return {
          formdata: {},
          userId: yufp.session.userId,
          dataRoot: { orgId: yufp.session.org.id, orgName: yufp.session.org.name },
          dataParams: { orgSts: 'A', lazy: true },
          height: yufp.custom.viewSize().height - 152,
          treeUrl: backend.appOcaService + '/api/util/getorg',
          roleUserUrl: backend.appOcaService + '/api/adminsmrole/roleuser',
          userUrl: backend.appOcaService + '/api/adminsmuser/querypage',
          styleObj: { height: yufp.custom.viewSize().height + 'px', overflow: 'auto' },
          mainGrid: {
            data: null,
            total: null,
            loading: false,
            multipleSelection: [],
            query: {
              orgId: '',
              roleCode: '',
              roleName: '',
              roleSts: ''
            },
            height: yufp.custom.viewSize().height - 150,
            checkbox: true,
            dataUrl: backend.appOcaService + '/api/adminsmrole/querypage',
            currentRow: null,
            dataParams: {
              condition: JSON.stringify({
                orgId: yufp.session.org.id
              })
            },
            tableColumns: [
              { label: this.$t('roleManage.jsdm'), prop: 'roleCode', resizable: true },
              { label: this.$t('roleManage.jsmc'), prop: 'roleName', resizable: true },
              { label: this.$t('roleManage.zt'), prop: 'roleSts', width: 90, resizable: true,
                template: function () {
                  return '<template scope="scope">\
                  <yu-tag type="success" v-if="scope.row.roleSts == \'A\' ">生效</yu-tag>\
                  <yu-tag type="warning" v-if="scope.row.roleSts == \'W\' ">待生效</yu-tag>\
                  <yu-tag type="danger" v-if="scope.row.roleSts == \'I\' ">失效</yu-tag>\
                  </template>';
                } 
              },
              { label: this.$t('roleManage.ssjg'), prop: 'orgName', resizable: true },
              { label: this.$t('roleManage.zxbgyh'), prop: 'userName', resizable: true },
              { label: this.$t('roleManage.zxbgsj'), prop: 'lastChgDt', type: 'date', resizable: true }
            ]
          },
          updateFields: [{
            columnCount: 1,
            fields: [
              {
                field: 'roleCode',
                label: this.$t('roleManage.jsdm'),
                rules: [{ required: true, message: this.$t('roleManage.btx'), trigger: 'blur' }]
              },
              {
                field: 'roleName',
                label: this.$t('roleManage.jsmc'),
                rules: [{ required: true, message: this.$t('roleManage.btx'), trigger: 'blur' }]
              },
              {
                label: this.$t('roleManage.ssjg'),
                field: 'orgId',
                type: 'custom',
                is: 'yufp-org-tree',
                params: {
                  lazy: true,
                  needCheckbox: false,
                  dataRoot: { orgId: yufp.session.org.id, orgName: yufp.session.org.name },
                  dataParams: {
                    needDpt: true,
                    orgSts: 'A',
                    lazy: true
                  }
                },
                rules: [{ required: true, message: this.$t('roleManage.btx'), trigger: 'blur' }]
              },
              {
                field: 'roleSts',
                label: this.$t('roleManage.zt'),
                type: 'select',
                dataCode: 'DATA_STS',
                rules: [{ required: true, message: this.$t('roleManage.btx'), trigger: 'blur' }]
              }
            ]
          }],
          updateButtons: [
            {
              label: this.$t('roleManage.bc'),
              type: 'primary',
              op: 'submit',
              hidden: false,
              click: function (model) {
                me.saveCreateFn();
              }
            },
            {
              label: this.$t('roleManage.qx'),
              hidden: false,
              click: function (model) {
                me.dialogFormVisible = false;
              }
            }],
          // 角色用户
          userMap: {
            roleUser: this.$t('roleManage.jsyh')
          },
          userTableColumns: [
            { label: this.$t('roleManage.dldm'), prop: 'loginCode', width: 180 },
            { label: this.$t('roleManage.ygxm'), prop: 'userName', sortable: true, resizable: true },
            { label: this.$t('roleManage.ssjg'), prop: 'orgName', width: 180 }
          ],
          userQueryFields: [
            { placeholder: this.$t('roleManage.dldm'), field: 'loginCode', type: 'input' },
            { placeholder: this.$t('roleManage.ygxm'), field: 'userName', type: 'input' },
            { placeholder: this.$t('roleManage.ygh'), field: 'userCode', type: 'input' }
          ],
          userQueryButtons: [
            {
              label: this.$t('roleManage.ss'),
              op: 'submit',
              type: 'primary',
              click: function (model, valid) {
                if (valid) {
                  var param = {
                    condition: JSON.stringify({
                      loginCode: me.$refs.userQuery.fm.loginCode ? me.$refs.userQuery.fm.loginCode : null,
                      userName: me.$refs.userQuery.fm.userName ? me.$refs.userQuery.fm.userName : null,
                      userCode: me.$refs.userQuery.fm.userCode ? me.$refs.userQuery.fm.userCode : null,
                      userSts: me.$refs.userQuery.fm.userSts ? me.$refs.userQuery.fm.userSts : null,
                      roleId: me.$refs.roletable.selections[0].roleId
                    })
                  };
                  me.$refs.userTable.remoteData(param);
                }
              }
            },
            {
              label: this.$t('roleManage.zz'),
              op: 'reset',
              click: function () { }
            }
          ],
          viewType: 'DETAIL',
          org: {
            treeUrl: '',
            dataRoot: yufp.session.org.code
          },
          userGrid: {
            userTableColumns: [
              { label: this.$t('roleManage.dldm'), prop: 'loginCode', width: 180 },
              { label: this.$t('roleManage.ygxm'), prop: 'userName', sortable: true, resizable: true },
              { label: this.$t('roleManage.ssbm'), prop: 'dptName', width: 180 }
            ],
            userQueryFields: [{ placeholder: this.$t('roleManage.dldmxmygh'), field: 'userInfo', type: 'input' }],
            dataParams: {
              condition: JSON.stringify({
                userSts: 'A',
                orgId: yufp.session.org.id
              })
            },
            userQueryButtons: [
              {
                label: this.$t('roleManage.ss'),
                op: 'submit',
                type: 'primary',
                click: function (model, valid) {
                  if (valid) {
                    var param = {
                      condition: JSON.stringify({
                        userInfo: me.$refs.userQuery1.fm.userInfo ? me.$refs.userQuery1.fm.userInfo : null
                      })
                    };
                    me.$refs.userSelectTable.remoteData(param);
                  }
                }
              },
              {
                label: this.$t('roleManage.zz'),
                op: 'reset',
                click: function () { }
              }
            ]
          },
          switchStatus: function (viewType, editable) {
            this.viewType = viewType;
            this.dialogVisible = true;
            this.formDisabled = !editable;
            this.updateButtons[0].hidden = !editable;
            if (viewType == 'DETAIL') {
              this.updateButtons[1].hidden = !editable;
            }
          },
          dialogStatus: '',
          formDisabled: false,
          dialogFormVisible: false, // from弹窗
          dialogGridVisible: false, // 编辑列表弹窗
          dialogUserVisible: false, // 角色用户新增选择
          dialogDisabled: true,
          viewTitle: yufp.lookup.find('CRUD_TYPE', false),
          yourVal: '',
          rawValue: '',
          // 默认权限  add by chenlin2
          authMap: {
            'authTitle': this.$t('roleManage.mrqx')
          },
          authDialogVisible: false,
          authUrl: backend.appOcaService + '/api/adminsmrole/roleauth',
          authTableColumns: [
            { label: this.$t('roleManage.mbmc'), prop: 'authTmplName', width: 150 },
            { label: this.$t('roleManage.sjqxtj'), prop: 'sqlString', width: 300 },
            { label: this.$t('roleManage.zxbgyh'), prop: 'userName', resizable: true },
            {
              label: this.$t('roleManage.zxbgsj'),
              prop: 'lastChgDt',
              type: 'date',
              resizable: true,
              formatter: function (row, me) {
                return row.lastChgDt.substring(0, 10);
              }
            }
          ],
          expandName: ['authAdd', 'authList'],
          authAddUrl: '',
          authAddColumns: [
            { label: this.$t('roleManage.mbm'), prop: 'authTmplName', width: 150, sortable: true, resizable: true },
            { label: this.$t('roleManage.sjqxtj'), prop: 'sqlString', width: 300 },
            { label: this.$t('roleManage.zxbgyh'), prop: 'lastChgUsr' },
            { label: this.$t('roleManage.zxbgsj'), prop: 'lastChgDt' }
          ]
        };
      },
      methods: {
        queryMainGridFn: function () {
          var me = this;
          var param = {
            condition: JSON.stringify({
              orgId: this.mainGrid.query.orgId ? this.mainGrid.query.orgId : yufp.session.org.id,
              roleCode: this.mainGrid.query.roleCode ? this.mainGrid.query.roleCode : null,
              roleName: this.mainGrid.query.roleName ? this.mainGrid.query.roleName : null,
              roleSts: this.mainGrid.query.roleSts ? this.mainGrid.query.roleSts : null,
              orgType: this.mainGrid.query.orgType ? this.mainGrid.query.orgType : null
            })
          };
          me.$refs.roletable.remoteData(param);
          // 发起请求
          yufp.service.request({
            method: 'GET',
            url: backend.appOcaService + '/api/adminsmrole/querypage',
            data: param,
            callback: function (code, message, response) {
              me.mainGrid.data = response.data;
              me.mainGrid.total = response.total;
              me.mainGrid.loading = false;
            }
          });
        },
        // 点击树查询
        nodeClickFn: function (node, obj, nodeComp) {
          if (node != '') {
            orgId = node.id;
            this.nowNode = node;
            this.mainGrid.query.orgId = node.orgCode;
            this.mainGrid.query.orgType = node.orgType;
            this.queryMainGridFn();
          }
        },
        // 新增面板弹出
        openCreateFn: function () {
          // this.userGrid.query.roleId = '';
          this.dialogDisabled = false;
          this.dialogFormVisible = true;
          this.switchStatus('ADD', true);
          this.$nextTick(function () {
            this.$refs.roleForm.resetFields();// 重置form
            this.$refs.roleForm.formModel.roleSts = 'A';
            this.$refs.roleForm.formModel.orgId = orgId;
          });
        },
        // 保存方法
        saveCreateFn: function () {
          var me = this;
          var roleForm = me.$refs.roleForm;
          roleForm.validate(function (valid) {
            var comitData = {};
            if (roleForm.formModel.roleId == '' || typeof roleForm.formModel.roleId == 'undefined') {
              // 新增时保存
              delete roleForm.formModel.roleId;
              if (valid) {
                yufp.service.request({
                  method: 'GET',
                  url: backend.appOcaService + '/api/adminsmrole/createcheckrolecode',
                  data: {
                    roleCode: roleForm.formModel.roleCode
                  },
                  callback: function (code, message, response) {
                    if (response > 0) {
                      me.$message({ message: me.$t('roleManage.jsdmcf'), type: 'warning' });
                    } else {
                      yufp.extend(comitData, roleForm.formModel);
                      comitData.roleCode = roleForm.formModel.roleCode;
                      comitData.roleName = roleForm.formModel.roleName;
                      comitData.orgId = roleForm.formModel.orgId;
                      comitData.lastChgUsr = yufp.session.userId;
                      yufp.service.request({
                        method: 'POST',
                        url: backend.appOcaService + '/api/adminsmrole/createrole',
                        data: comitData,
                        callback: function (code, message, response) {
                          me.dialogFormVisible = false;
                          me.dialogVisible = false;
                          me.$message({ message: me.$t('roleManage.sjbccg') });
                          me.queryMainGridFn();
                        }
                      });
                    }
                  }
                });
              }
            } else {
              // 修改时保存
              if (valid) {
                yufp.service.request({
                  method: 'GET',
                  url: backend.appOcaService + '/api/adminsmrole/editcheckrolecode',
                  data: {
                    roleCode: roleForm.formModel.roleCode,
                    roleId: roleForm.formModel.roleId
                  },
                  callback: function (code, message, response) {
                    if (response > 0) {
                      me.$message({ message: me.$t('roleManage.jsdmcf'), type: 'warning' });
                    } else {
                      yufp.extend(comitData, roleForm.formModel);
                      comitData.roleCode = roleForm.formModel.roleCode;
                      comitData.roleName = roleForm.formModel.roleName;
                      comitData.orgId = roleForm.formModel.orgId;
                      comitData.lastChgUsr = yufp.session.userId;
                      yufp.service.request({
                        method: 'POST',
                        url: backend.appOcaService + '/api/adminsmrole/editrole',
                        data: comitData,
                        callback: function (code, message, response) {
                          me.dialogFormVisible = false;
                          me.dialogVisible = false;
                          me.$message({ message: me.$t('roleManage.sjbccg') });
                          me.queryMainGridFn();
                        }
                      });
                    }
                  }
                });
              }
            }
          });
        },
        // 修改
        modifyFn: function () { // 修改弹出方法
          if (this.$refs.roletable.selections.length != 1) {
            this.$message({ message: this.$t('roleManage.qxzytjl'), type: 'warning' });
            return;
          }
          if (this.$refs.roletable.selections[0].roleSts == 'A') {
            this.$message({ message: this.$t('roleManage.znxzsxhdsxdsj'), type: 'warning' });
            return;
          }
          this.dialogFormVisible = true;
          this.dialogDisabled = false;
          this.dialogFormVisible = true;
          this.switchStatus('EDIT', true);
          this.$nextTick(function () {
            yufp.extend(this.$refs.roleForm.formModel, this.$refs.roletable.selections[0]);
          });
        },
        infoFn: function () { // 详情弹出方法
          if (this.$refs.roletable.selections.length != 1) {
            this.$message({ message: this.$t('roleManage.qxzytjl'), type: 'warning' });
            return;
          }
          this.dialogFormVisible = true;
          this.dialogDisabled = false;
          this.dialogFormVisible = true;
          this.switchStatus('DETAIL', true);
          this.$nextTick(function () {
            yufp.extend(this.$refs.roleForm.formModel, this.$refs.roletable.selections[0]);
          });
        },
        openEditFn: function (row) {
          if (this.$refs.roletable.selections.length !== 1) {
            this.$message({ message: this.$t('roleManage.qxzytsj'), type: 'warning' });
            return false;
          }
          var row = this.$refs.roletable.selections[0];
          if (row.roleSts === 'A') {
            this.$message({ message: this.$t('roleManage.znxztyhdqydsj'), type: 'warning' });
            return;
          }
          this.dialogStatus = 'update';

          this.dialogFormVisible = true;
          this.formDisabled = false;
          this.$nextTick(function () {
            yufp.extend(this.$refs.myform.formModel, row);
            yufp.extend(this.$refs.myform1.formModel, row);
          });
        },
        // 启用方法
        useFn: function () {
          var vue = this;
          if (this.$refs.roletable.selections.length > 0) {
            var id = '';
            var userId = yufp.session.userId;
            for (var i = 0; i < this.$refs.roletable.selections.length; i++) {
              var row = this.$refs.roletable.selections[i];
              if (row.roleSts === 'W' || row.roleSts === 'I') {
                id = id + ',' + row.roleId;
              } else {
                vue.$message({ message: vue.$t('roleManage.znxzsxhdsxdsj'), type: 'warning' });
                return;
              }
            }
            this.$confirm(this.$t('roleManage.cczjqygjssfjx'), this.$t('roleManage.ts'), {
              confirmButtonText: this.$t('roleManage.qr'),
              cancelButtonText: this.$t('roleManage.qx'),
              type: 'warning'
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                url: backend.appOcaService + '/api/adminsmrole/usebatch',
                data: {
                  id: id,
                  userId: userId
                },
                callback: function (code, message, response) {
                  vue.$message({ message: response.message });
                  vue.queryMainGridFn();
                }
              });
            });
          } else {
            this.$message({ message: this.$t('roleManage.qxxzysxdsj'), type: 'warning' });
            return;
          }
        },
        // 停用方法
        unUseFn: function () { // 批量失效
          var vue = this;
          var userId = yufp.session.userId;
          if (this.$refs.roletable.selections.length > 0) {
            var id = '';
            for (var i = 0; i < this.$refs.roletable.selections.length; i++) {
              var row = this.$refs.roletable.selections[i];
              if (row.roleSts === 'A') {
                id = id + ',' + row.roleId;
              } else {
                this.$message({ message: this.$t('roleManage.znxzsxdsj'), type: 'warning' });
                return;
              }
            }
            this.$confirm(this.$t('roleManage.cczjtygjssfjx'), this.$t('roleManage.ts'), {
              confirmButtonText: this.$t('roleManage.qr'),
              cancelButtonText: this.$t('roleManage.qx'),
              type: 'warning'
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                url: backend.appOcaService + '/api/adminsmrole/unusebatch',
                data: {
                  id: id,
                  userId: userId
                },
                callback: function (code, message, response) {
                  if (code == 0) {
                    vue.$message({ message: response.data.message });
                    vue.queryMainGridFn();
                  }
                }
              });
            });
          } else {
            this.$message({ message: this.$t('roleManage.qxxzytydsj'), type: 'warning' });
            return;
          }
        },
        // 删除方法
        deleteFn: function () {
          var vue = this;
          if (this.$refs.roletable.selections.length > 0) {
            var id = '';
            for (var i = 0; i < this.$refs.roletable.selections.length; i++) {
              var row = this.$refs.roletable.selections[i];
              if (row.roleSts != 'A') {
                id = id + ',' + row.roleId;
              } else {
                this.$message({ message: this.$t('roleManage.znscdsxhsxdsj'), type: 'warning' });
                return;
              }
            }
            this.$confirm(this.$t('roleManage.cczjscgjsxxsfjx'), this.$t('roleManage.ts'), {
              confirmButtonText: this.$t('roleManage.qr'),
              cancelButtonText: this.$t('roleManage.qx'),
              type: 'warning'
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                url: backend.appOcaService + '/api/adminsmrole/deletebatch',
                data: {
                  ids: id
                },
                callback: function (code, message, response) {
                  if (code == '0' && response.code == 0) {
                    vue.$message({ message: response.data.message });
                    vue.queryMainGridFn();
                  }
                }
              });
            }).catch(function () {
              return;
            });
          } else {
            this.$message({ message: this.$t('roleManage.qxxzyscdsj'), type: 'warning' });
            return;
          }
        },
        // //角色用户
        openRoleUserFn: function () {
          if (this.$refs.roletable.selections.length != 1) {
            this.$message({ message: this.$t('roleManage.qxxzytjl'), type: 'warning' });
            return;
          }
          this.dialogDisabled = false;
          this.dialogStatus = 'roleUser';
          this.dialogGridVisible = true;
          this.queryUserGridFn();
        },
        queryUserGridFn: function () {
          var me = this;
          this.$nextTick(function () {
            var param = {
              condition: JSON.stringify({
                loginCode: me.$refs.userQuery.fm.loginCode ? me.$refs.userQuery.fm.loginCode : null,
                userName: me.$refs.userQuery.fm.userName ? me.$refs.userQuery.fm.userName : null,
                userCode: me.$refs.userQuery.fm.userCode ? me.$refs.userQuery.fm.userCode : null,
                userSts: me.$refs.userQuery.fm.userSts ? me.$refs.userQuery.fm.userSts : null,
                roleId: me.$refs.roletable.selections[0].roleId
              })
            };
            me.$refs.userTable.remoteData(param);
          });
        },

        // 默认权限 begin  add by chenlin
        openRoleAuthFn: function () { // 打开默认权限页面
          if (this.$refs.roletable.selections.length != 1) {
            this.$message({ message: this.$t('roleManage.qxxzytjl'), type: 'warning' });
            return;
          }
          var me = this;
          this.dialogDisabled = false;
          this.dialogStatus = 'authTitle';
          this.authDialogVisible = true;
          this.queryUserAuthFn();
          this.$nextTick(function () {
            // me.$refs.authAddTable.data = '';
            me.$refs.demoSelector.selectedVal = '';
          });
        },
        queryUserAuthFn: function () { // 查询默认权限
          var me = this;
          this.$nextTick(function () {
            var param = {
              condition: JSON.stringify({
                roleId: me.$refs.roletable.selections[0].roleId ? me.$refs.roletable.selections[0].roleId : null
              })
            };
            me.$refs.authTable.remoteData(param);
          });
        },
        // 选择数据加入待确认列表
        selectFn: function (a, b) {
          var authAddList = [];
          authAddList.push(
            {

              authTmplName: b.authTmplName,
              sqlString: b.sqlString,
              lastChgUsr: b.lastChgUsr,
              lastChgDt: b.lastChgDt
            }
          );
          this.$refs.authAddTable.data = authAddList;
        },
        saveUserAuth: function () { // 保存、修改默认权限
          if (this.yourVal == '') {
            this.$message({ message: this.$t('roleManage.qxxzqxmb'), type: 'warning' });
            return;
          }
          var vue = this;
          var length = this.$refs.authTable.data.length;
          var params = {
            sysId: yufp.session.logicSys.id, // 逻辑系统id
            lastChgUsr: yufp.session.userId, // 用户id
            authobjId: this.$refs.roletable.selections[0].roleId, // 角色id
            authresId: this.yourVal// 模板id
          };
          if (length > 0) {
            vue.$confirm(vue.$t('roleManage.cczjsdqrmbthmrmbsfjx'), vue.$t('roleManage.ts'), {
              confirmButtonText: vue.$t('roleManage.qr'),
              cancelButtonText: vue.$t('roleManage.qx'),
              type: 'warning'
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                url: backend.appOcaService + '/api/adminsmrole/updateroleauth',
                data: {
                  authId: vue.$refs.authTable.data[0].authId,
                  userId: yufp.session.userId, // 用户id
                  authTmplId: vue.yourVal// 模板id
                },
                callback: function (code, message, response) {
                  vue.$message({ message: vue.$t('roleManage.mrqxszxgcg') });
                  vue.authDialogVisible = false;
                  vue.dialogVisible = false;
                  vue.$refs.authAddTable.data = '';
                  vue.$refs.demoSelector.selectedVal = '';
                  vue.queryMainGridFn();
                }
              });
            }).catch(function () {
              return;
            });
          } else {
            yufp.service.request({
              method: 'POST',
              url: backend.appOcaService + '/api/adminsmrole/saveroleauth',
              data: params,
              callback: function (code, message, response) {
                vue.$message({ message: vue.$t('roleManage.mrqxszxzcg') });
                vue.authDialogVisible = false;
                vue.dialogVisible = false;
                vue.$refs.authAddTable.data = '';
                vue.$refs.demoSelector.selectedVal = '';
                vue.queryMainGridFn();
              }
            });
          }
        },
        // 取消选择
        selectCancel: function () {
          this.$refs.authAddTable.data = '';
          this.$refs.demoSelector.selectedVal = '';
        },
        cleanAuthFn: function () {
          var vue = this;
          if (vue.$refs.authTable.data.length == 0) {
            vue.$message({ message: vue.$t('roleManage.bczmrqx'), type: 'warning' });
            return false;
          }
          vue.$confirm(vue.$t('roleManage.cczjqcmrqxsfjx'), vue.$t('roleManage.ts'), {
            confirmButtonText: vue.$t('roleManage.qr'),
            cancelButtonText: vue.$t('roleManage.qx'),
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              method: 'GET',
              url: backend.appOcaService + '/api/adminsmrole/cleanroleauth',
              data: {
                authId: vue.$refs.authTable.data[0].authId
              },
              callback: function (code, message, response) {
                vue.yourVal = '';
                vue.queryUserAuthFn();
                vue.$message({ message: vue.$t('roleManage.mrqxszxgcg') });
              }
            });
          });
        },
        // 默认权限 end

        /**
             * @name: addRoleUserFn
             * @author: yangxiao2
             * @description: 角色用户新增
             */
        addRoleUserFn: function () {
          var _this = this;
          _this.dialogUserVisible = true;
        },
        /**
             * @name: cancelUserRole
             * @author: yangxiao2
             * @description: 角色用户新增取消
             */
        cancelUserRole: function () {
          var _this = this;
          _this.dialogUserVisible = false;
        },
        /**
             * @name: saveUserRole
             * @author: yangxiao2
             * @description: 角色用户新增保存
             */
        saveUserRole: function () {
          var _this = this;
          var selections = _this.$refs.userSelectTable.selections;
          if (selections.length < 0) {
            _this.$message({ message: _this.$t('roleManage.qxxzytsj'), type: 'warning' });
            return;
          }
          _this.$confirm(_this.$t('roleManage.qrwxqdjsxzyh'), _this.$t('roleManage.ts'), {
            confirmButtonText: _this.$t('roleManage.qr'),
            cancelButtonText: _this.$t('roleManage.qx'),
            type: 'warning'
          }).then(function () {
            var ids = '';
            for (var i = 0; i < selections.length; i++) {
              ids += selections[i].userId + ',';
            }
            var roleId = _this.$refs.roletable.selections[0].roleId;
            var param = {
              ids: ids,
              roleId: roleId,
              lastChgUsr: yufp.session.userId
            };
            yufp.service.request({
              method: 'POST',
              url: backend.appOcaService + '/api/adminsmrole/addroleuser',
              data: param,
              callback: function (code, message, response) {
                if (response.code == 0) {
                  _this.$refs.userTable.remoteData();
                  _this.$message({ message: _this.$t('roleManage.tjjsyhcg') });
                  _this.dialogUserVisible = false;
                } else if (response.code == -2) {
                  _this.$message({ message: response.message + _this.$t('roleManage.glsjyjcz'), type: 'warning' });
                } else {
                  _this.$message({ message: _this.$t('roleManage.tjjsyhsb'), type: 'warning' });
                }
              }
            });
          });
        },
        /**
             * @name: delRoleUserFn
             * @author: yangxiao2
             * @description: 角色用户剔除
             */
        delRoleUserFn: function () {
          var _this = this;
          var selections = _this.$refs.userTable.selections;
          if (selections.length < 1) {
            _this.$message({ message: _this.$t('roleManage.qxxzytsj'), type: 'warning' });
            return;
          }
          _this.$confirm(_this.$t('roleManage.cczjtcsxyhjssfjx'), _this.$t('roleManage.ts'), {
            confirmButtonText: _this.$t('roleManage.qr'),
            cancelButtonText: _this.$t('roleManage.qx'),
            type: 'warning'
          }).then(function () {
            var ids = '';
            for (var i = 0; i < selections.length; i++) {
              ids += selections[i].userId + ',';
            }
            var roleId = _this.$refs.roletable.selections[0].roleId;
            var param = {
              ids: ids,
              roleId: roleId
            };
            yufp.service.request({
              method: 'POST',
              url: backend.appOcaService + '/api/adminsmrole/delroleuser',
              data: param,
              callback: function (code, message, response) {
                if (response.code == 0) {
                  _this.$refs.userTable.remoteData();
                  _this.$message({ message: _this.$t('roleManage.scjsyhcg') });
                  _this.dialogUserVisible = false;
                } else {
                  _this.$message({ message: _this.$t('roleManage.scjsyhsb'), type: 'warning' });
                }
              }
            });
          });
        }
      }
    });
  };
});
